#pragma once

#include <stdint.h>
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
#include <string>
#include "QueryResult.h"

#define MAX_QUERY_LEN 1024

class DatabaseMysql
{
public:
    struct DatabaseInfo
    {
        std::string strHost;
        std::string strUser;
        std::string strPwd;
        std::string stdDBName;
    };

    DatabaseMysql();
    ~DatabaseMysql();

    bool initialize(const std::string &host,const std::string& user,const std::string& pwd,const std::string& dbname);

    QueryResult* query(const char* mysql); 
    QueryResult* query(const std::string& sql); 
    QueryResult* pQuery(const char* format, ...);

    bool execute(const char* sql);
    bool execute(const char* sql,uint32_t& uAffectedCount,int& nErrno);
    bool execute(const char* format, ...);

    uint32_t getInsertID();
    void clearStoredResults();
    int32_t escapeString(char* szDst,const char* szSrc,uint32_t uSize); 

private:
    DatabaseInfo m_DBInfo;
    MYSQL*       m_mysql;
    bool         m_bInit;
};